var ec2ui_HealthcheckTreeView = {
    COLNAMES : ['Healthcheck.Interval','Healthcheck.HealthyThreshold','Healthcheck.Timeout','Healthcheck.UnhealthyThreshold'],
    treeBox : null,
    selection : null,
    healthckeckList : new Array(),

    get rowCount() { return this.healthckeckList.length; },

    setTree     : function(treeBox)     { this.treeBox = treeBox; },
    getCellText : function(idx, column) {
        if (idx >= this.rowCount) return "";
        var member = column.id.split(".").pop();
        return this.healthckeckList[idx][member];
    },
    isEditable: function(idx, column)  { return true; },
    isContainer: function(idx)         { return false;},
    isSeparator: function(idx)         { return false; },
    isSorted: function()               { return false; },

    getImageSrc: function(idx, column) { return ""; },
    getProgressMode : function(idx,column) {},
    getCellValue: function(idx, column) {},
    cycleHeader: function(col) {
        var Healthcheck = this.getSelectedHealthcheck();
        cycleHeader(
            col,
            document,
            this.COLNAMES,
            this.healthckeckList);
        this.treeBox.invalidate();
        if (Healthcheck) {
            log(perm.id + ": Select this Healthcheck sort");
            this.selectByHealthcheck(Healthcheck);
        } else {
            log("The selected Healthcheck is null!");
        }
    },
    

    selectByHealthcheck : function(Healthcheck) {
        this.selection.clearSelection();
        var HealthcheckStr = encodeJSONMap(Healthcheck);
        for(var i in this.HealthcheckList) {
            var curr = encodeJSONMap(this.HealthcheckList[i]);
            if (curr == HealthcheckStr) {
                this.selection.select(i);
                this.treeBox.ensureRowIsVisible(i);
                return;
            }
        }

        // In case we don't find a match (which is probably a bug).
        this.selection.select(0);
    },

    sort : function() {
        sortView(document, this.COLNAMES, this.HealthcheckList);
    },

    selectionChanged: function() {},
    cycleCell: function(idx, column) {},
    performAction: function(action) {},
    performActionOnCell: function(action, index, column) {},
    getRowProperties: function(idx, column, prop) {},
    getCellProperties: function(idx, column, prop) {},
    getColumnProperties: function(column, element, prop) {},
    getLevel : function(idx) { return 0; },

    

    getSelectedHealthcheck : function() {
        var index =  this.selection.currentIndex;
        if (index == -1) return null;
        return this.HealthcheckList[index];
    },

   

    displayHealthcheck : function (HealthcheckList) {
        this.treeBox.rowCountChanged(0, -this.HealthcheckList.length);
        this.HealthcheckList = HealthcheckList;
        this.treeBox.rowCountChanged(0, this.HealthcheckList.length);
        this.sort();
        this.selection.clearSelection();
        if (HealthcheckList.length > 0) {
            this.selection.select(0);
        }
    }
};
